/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hcmus.fit.master.sevensea.sprite;

import hcmus.fit.master.sevensea.background.Sea;
import hcmus.fit.master.sevensea.core.AbstractSprite;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;

/**
 * 
 * @author hvp
 */
public class Splash extends AbstractSprite {
    public static List<List<Bitmap>> Resource;

    public Splash(Sea seaMap, int x, int y) {
        super(seaMap, x, y);
        setFrames(Resource.get(0));
        setNbOfFrame(getFrames().size());
    }

    public boolean update() {
        setIndex(getIndex() + 1);
        if (getIndex() >= getNbOfFrame()) {
            getSeaMap().items.remove(this);
            if (getSeaMap().win()) {
                if (getSeaMap().close()) {
                    if (getSeaMap().boardControl._Life.LIFE <= 1) {
                        getSeaMap().gameOver();
                        return false;
                    } else {
                        getSeaMap().boardControl._Life.LIFE--;
                    }
                }
                getSeaMap().nextLevel();
                return false;
            }
            if (getSeaMap().close()) {
                if (getSeaMap().boardControl._Life.LIFE <= 1) {
                    getSeaMap().gameOver();
                } else {
                    getSeaMap().boardControl._Life.LIFE--;
                    getSeaMap().reloadCurrentLevel();
                }
                return false;
            }
        }
        return true;
    }

    public static List<List<Bitmap>> GetResource(Bitmap resource, int maxX, int maxY, int numerator,
            int denominator) {
        List<List<Bitmap>> rs = new ArrayList<List<Bitmap>>();
        int w = resource.getWidth() / maxX;
        int h = resource.getHeight() / maxY;
        try {
            List<Bitmap> tmp = new ArrayList<Bitmap>();
            for (int i = 0; i < maxX; i++) {
                tmp.add(Bitmap.createBitmap(resource, i * w, 0, w, h));
            }
            rs.add(tmp);
        } catch (Exception ex) {
        }
        return rs;
    }
}
